<?php

use App\Models\ConfigWithdraw;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateConfigWithdrawsTable extends Migration
{
    public function up()
    {
        Schema::create('config_withdraws', function (Blueprint $table) {
            $table->id();
	        $table->boolean('is_open')->default(true);
	        $table->boolean('is_local')->default(true);
	        $table->string('allowed_channel')->default('local')->comment('local, freelance');
	        $table->text('allowed_methods')->nullable()->comment('all available methods of withdraw');
	        $table->text('allowed_weekdays')->nullable()->comment('when users are allowed to withdraw');
	        $table->decimal('allowed_lowest_amount', 10, 2)->default(10)->comment('at least has this amount in user account before withdraw');
	        $table->decimal('allowed_highest_amount', 10, 2)->default(10000)->comment('the highest money which user can withdraw each time');
	        $table->unsignedInteger('multiple')->default(0)->comment('the money withdrawed must follow this integer multiple');

            /**
	         * in:  提现金额内扣除，实际到账金额小于提现金额
	         * out: 提现金额外扣除，实际到账金额等于提现金额
	         */
	        $table->string('charge_type')->default('in')->comment('deduct service charge from the amount of withdraw money or of user total money');
	        $table->unsignedInteger('charge_percent')->default(3)->comment('how much service charge pay to this platform');
	        $table->decimal('allowed_lowest_charge', 10, 2)->default(0.3)->comment('if the money withdrawing less than amount this then deduct this amount');
	        $table->decimal('allowed_highest_charge', 10, 2)->default(0.00)->comment('if the money withdrawing greater than this amount then deduct this amount');
	        $table->unsignedInteger('frequency')->default(1)->comment('how much times user allows withdrawing each day');
	        $table->text('description')->nullable()->comment('remark');
        });

	    ConfigWithdraw::create(['allowed_methods' => ["wxpay"], 'allowed_weekdays' => ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]]);
    }

    public function down()
    {
        Schema::dropIfExists('config_withdraws');
    }
}
